import numpy as np


def poisson_finite_difference(N):
# delta_x
    delta_x = 1 / N
#    zeros
    A = np.zeros((N, N))
    b = np.zeros(N)

# 填充系数矩阵和常数向量
    for i in range(1, N-1):
        A[i, i-1] = 1 / (delta_x ** 2)
        A[i, i] = -2 / (delta_x ** 2)
        A[i, i+1] = 1 / (delta_x ** 2)
        b[i] = 1


    A[0, 0] = 0
    A[0, 1] = 1 / (delta_x ** 2)
    A[N-1, N-1] = 0
    A[N-1, N-2] = 1 / (delta_x ** 2)

    b[0] = 0
    b[N-1] = 0

# linalg.solve 求解方程组

    u = np.linalg.solve(A, b)

    return u
